﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Purdue.Extensions
{
    public static class EnumeratorExtensions
    {
        #region IEnumerator extensions

        public static IEnumerator Skip(this IEnumerator self, int numberOfItems)
        {
            if (self == null)
                throw new ArgumentNullException("self");

            for (int i = 0; i < numberOfItems; i++)
            {
                if (!self.MoveNext())
                    break;
            }

            return self;
        }

        public static IList<T> Take<T>(this IEnumerator<T> self, int numberOfItems)
        {
            if (self == null)
                throw new ArgumentNullException("self");

            List<T> cache = new List<T>(numberOfItems);

            for (int i = 0; i < numberOfItems; i++)
            {
                if (!self.MoveNext())
                    break;

                cache.Add(self.Current);
            }

            return cache;
        }

        #endregion
    }
}
